package com.owbtgad.common.utils;

import android.content.Context;


public class AppCache {
    public static final String WX_APPID = "wx63fbc756e80faef3";    //申请的wx appid
    public static final String QQ_APPID = "1110377485";    //申请的qq appid
    public static String packageName = "";
    private static boolean isHasMainActivity = false;//是否创建MainActivity
    private static boolean isBackstage = false;//是否在前台
    private static boolean isFront;//web是否刷新 前后台切换
    private static Context context;
    private static String userName;//用户名
    private static String accessToken;//登录令牌，所有非刷新令
    private static String authCode;//加密串
    private static String headId = "1";//
    private static String appKey = "loanUnion";//应用key，
    private static String channel = "s";//渠道
    private static String userId;//用户id
    private static String userPhone;//用户

    public static boolean isHasMainActivity() {
        return isHasMainActivity;
    }

    public static void setIsHasMainActivity(boolean isHasMainActivity) {
        AppCache.isHasMainActivity = isHasMainActivity;
    }

    public static boolean isBackstage() {
        return isBackstage;
    }

    public static void setIsBackstage(boolean isBackstage) {
        AppCache.isBackstage = isBackstage;
    }

    public static String getUserId() {

        return userId == null ? PrefUtils.getUserId() : userId;
    }

    public static void setUserId(String userId) {
        AppCache.userId = userId;
        PrefUtils.setUserId(userId);
    }

    public static String getUserPhone() {
        return userPhone == null ? PrefUtils.getUserPhone() : userPhone;
    }

    public static void setUserPhone(String userPhone) {
        AppCache.userPhone = userPhone;
        PrefUtils.setUserPhone(userPhone);
    }

    public static String getChannel() {
        return channel == null ? "" : channel;
    }

    public static void setChannel(String channel) {
        AppCache.channel = channel;
    }

    public static Context getContext() {
        return context;
    }

    public static void setContext(Context context) {
        AppCache.context = context;
    }

    public static String getPackageName() {
        return getContext().getPackageName() == null ? "" : getContext().getPackageName();
    }

    public static void setPackageName(String packageName) {
        AppCache.packageName = packageName;
    }

    public static String getUserName() {
//        return userName == null ? "70ca475b6ea9e966b78cf6c9e2673136" : userName;
        return userName == null ? PrefUtils.getUserName() : userName;
    }

    public static void setUserName(String userName) {
        AppCache.userName = userName;
        PrefUtils.setUserName(userName);
    }

    public static String getAuthCode() {
        return authCode == null ? PrefUtils.getAuthCode() : authCode;
    }

    public static void setAuthCode(String authCode) {
        AppCache.authCode = authCode;
        PrefUtils.setAuthCode(authCode);
    }

    public static boolean isLogin() {
        if (getAccessToken() != null && !getAccessToken().isEmpty()) {
            return true;
        } else {
            return false;
        }
    }

    public static String getAccessToken() {
        return accessToken == null ? PrefUtils.getToken() : accessToken;
    }

    public static void setAccessToken(String accessToken) {
        AppCache.accessToken = accessToken;
        PrefUtils.setToken(accessToken);
    }

    public static String getWxAppid() {
        return WX_APPID == null ? "" : WX_APPID;
    }

    public static String getQqAppid() {
        return QQ_APPID == null ? "" : QQ_APPID;
    }

    public static String getHeadId() {
        return headId == null ? "1" : headId;
    }

    public static void setHeadId(String headId) {
        AppCache.headId = headId;
    }

    public static boolean isFront() {
        return isFront;
    }

    public static void setIsFront(boolean isFront) {
        AppCache.isFront = isFront;
    }

    public static String getAppKey() {
        return appKey == null ? "" : appKey;
    }

    public static void setAppKey(String appKey) {
        AppCache.appKey = appKey;
    }
}
